package com.example.mentalhealthdiary.style;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import com.example.mentalhealthdiary.R;

/**
 * 卡芙卡AI界面风格
 */
public class KafkaStyle implements AIPersonalityStyle {
    private Context context;
    
    public KafkaStyle(Context context) {
        this.context = context;
    }
    
    @Override
    public int getChatBubbleDrawable(boolean isUser) {
        if (isUser) {
            return R.drawable.chat_bubble_sent;
        } else {
            return context.getResources().getIdentifier(
                context.getString(R.string.kafka_bubble_bg), 
                "drawable", 
                context.getPackageName()
            );
        }
    }
    
    @Override
    public int getInputBackgroundDrawable() {
        return context.getResources().getIdentifier(
            context.getString(R.string.kafka_input_bg), 
            "drawable", 
            context.getPackageName()
        );
    }
    
    @Override
    public int getBackgroundDrawable() {
        return context.getResources().getIdentifier(
            context.getString(R.string.kafka_chat_bg), 
            "drawable", 
            context.getPackageName()
        );
    }
    
    @Override
    public ColorStateList getPrimaryColor() {
        return ColorStateList.valueOf(context.getResources().getColor(R.color.kafka_primary));
    }
    
    @Override
    public int getHintTextColor() {
        return context.getResources().getColor(R.color.kafka_secondary);
    }
    
    @Override
    public Typeface getTypeface(Context context) {
        return FontHelper.loadTypeface(
            context,
            context.getString(R.string.kafka_font),
            "卡芙卡"
        );
    }
    
    @Override
    public String getInputHint() {
        return context.getString(R.string.kafka_input_hint);
    }
    
    @Override
    public String getSendButtonText() {
        return context.getString(R.string.kafka_send_button);
    }
    
    @Override
    public String transformText(String originalText) {
        if (originalText == null || originalText.isEmpty()) {
            return originalText;
        }
        
        // 已经有卡芙卡风格的不再处理
        if (originalText.contains("危险的心理游戏") || 
            originalText.contains("让姐姐")) {
            return originalText;
        }
        
        // 添加卡芙卡特色语气词
        String[] kafkaExpressions = {
            "（轻笑）", "（危险地微笑）", "（优雅地）", 
            "（低语）", "（魅惑地）"
        };
        
        // 随机选择表达方式
        String expression = kafkaExpressions[(int)(Math.random() * kafkaExpressions.length)];
        
        // 替换常见词语为卡芙卡风格
        originalText = originalText
            .replaceAll("(?i)我认为", "姐姐认为")
            .replaceAll("(?i)我想", "让姐姐想想")
            .replaceAll("(?i)请", "请让姐姐")
            .replaceAll("(?i)好的", "很好...")
            .replaceAll("(?i)不行", "这可不行呢...");
            
        // 处理句尾
        if (originalText.endsWith("。")) {
            originalText = originalText.substring(0, originalText.length()-1) + "... " + expression;
        } else if (!originalText.endsWith("...")) {
            originalText = originalText + "... " + expression;
        }
        
        return originalText;
    }
    
    @Override
    public int getButtonCornerRadius() {
        return (int) context.getResources().getDimension(R.dimen.kafka_button_radius);
    }
    
    @Override
    public int getButtonStrokeWidth() {
        return (int) context.getResources().getDimension(R.dimen.kafka_button_stroke_width);
    }
} 